package crmdna.program;

import java.util.List;

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Cache;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.Load;

import crmdna.common.DateUtils;
import crmdna.common.Utils.Currency;
import crmdna.group.GroupEntity;
import crmdna.programtype.ProgramTypeEntity;
import crmdna.teacher.TeacherEntity;
import crmdna.venue.VenueEntity;

@Entity
@Cache
public class ProgramEntity {

	@Id
	long programId;

	@Load
	@Index
	Ref<ProgramTypeEntity> programTypeRef;

	@Index
	int startYYYYMMDD;
	@Index
	int endYYYYMMDD;

	@Load
	@Index
	Ref<VenueEntity> venueRef;
	@Load
	@Index
	Ref<TeacherEntity> teacherRef;
	@Load
	@Index
	Ref<GroupEntity> groupRef;

	String description; // free text
	int numBatches;

	double fee;
	Currency ccy;

	List<String> batch1SessionTimings;
	List<String> batch2SessionTimings;
	List<String> batch3SessionTimings;
	List<String> batch4SessionTimings;
	List<String> batch5SessionTimings;

	String specialInstruction; // free text

	public ProgramProp toProp() {
		ProgramProp programProp = new ProgramProp();
		programProp.programId = programId;
		programProp.programTypeProp = programTypeRef.get().toProp();
		programProp.groupProp = groupRef.get().toProp();
		programProp.startYYYYMMDD = startYYYYMMDD;
		programProp.endYYYYMMDD = endYYYYMMDD;
		programProp.venueProp = venueRef.get().toProp();
		programProp.teacherProp = teacherRef.get().toProp();
		programProp.description = description;
		programProp.numBatches = numBatches;
		programProp.fee = fee;
		programProp.ccy = ccy;

		programProp.batch1SessionTimings = batch1SessionTimings;
		programProp.batch2SessionTimings = batch2SessionTimings;
		programProp.batch3SessionTimings = batch3SessionTimings;
		programProp.batch4SessionTimings = batch4SessionTimings;
		programProp.batch5SessionTimings = batch5SessionTimings;

		programProp.specialInstruction = specialInstruction;

		programProp.name = programProp.programTypeProp.displayName + " "
				+ DateUtils.getDurationAsString(startYYYYMMDD, endYYYYMMDD) + " @ "
				+ venueRef.get().toProp().displayName + " ("
				+ groupRef.get().toProp().displayName + ")";
		// eg: IshaKriya 3 Feb 2014 @ Woodlands CC (Singapore)

		return programProp;
	}
}
